import json
from dataclasses import asdict

from ..exception.customer_exception import CustomerException
from ..function.common_function import CommonFunction
from ..models.enums.app_http_code_enum import AppHttpCodeEnum
from ..models.vo.login_vo import LoginVo
from ..tests.case_collection.test_security_case import TestSecurityCase
from fastapi import APIRouter

router = APIRouter(prefix='/security', tags=['安全'])


@router.post('/login',
             summary='登录',
             description='登录',
             response_model=dict)
async def login(login_vo: LoginVo):
    if any([CommonFunction.is_blank(login_vo.applet_id), CommonFunction.is_blank(login_vo.clerk_name), CommonFunction.is_blank(login_vo.clerk_num), CommonFunction.is_blank(login_vo.applet_pwd)]):
        raise CustomerException(AppHttpCodeEnum.CLIENT_INIT_FAIL)
    try:
        response = TestSecurityCase().login_accord_applet_id_clerk_num_route1(login_vo.applet_id, login_vo.applet_pwd, login_vo.clerk_name, login_vo.clerk_num)
    except CustomerException as e:
        raise CustomerException(e.get_app_http_code_enum())
    return asdict(response)
